//
//  JCutHairShopCell.m
//  HeadIndustry
//
//  Created by jun on 2017/9/19.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JCutHairShopCell.h"

@interface JCutHairShopCell()

@property (nonatomic, strong)CALayer *imgLayer;
@property (nonatomic, strong)YYLabel *shopName;
@property (nonatomic, strong)YYLabel *shopDescribe;
@property (nonatomic, strong)YYLabel *menCount;
@property (nonatomic, strong)YYLabel *commentCount;
@property (nonatomic, strong)YYLabel *addressArea;
@property (nonatomic, strong)YYLabel *moreMsg;

@end

@implementation JCutHairShopCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.opaque = NO;
        [self setConfigBgView];
    }
    return self;
}

- (void)setConfigBgView
{
    CGFloat viewHeight = kWindowW/3.0 + 20 + 10;
    
    CGFloat imgWidth = kWindowW/3.0;
    CALayer *imgLayer = [CALayer layer];
    imgLayer.frame = CGRectMake(15, 10, imgWidth, imgWidth);
    [self.contentView.layer addSublayer:imgLayer];
    imgLayer.cornerRadius = 5;
    imgLayer.masksToBounds = YES;
    _imgLayer = imgLayer;
    
    YYLabel *name = [YYLabel new];
    name.top = 10;
    name.left = imgLayer.right + 10;
    name.size = CGSizeMake(kWindowW - imgLayer.right - 20, 40);
    name.numberOfLines = 2;
    name.font = kFONT_TITLE(16);
    name.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:name];
    _shopName = name;
    
    YYLabel *desLabel = [YYLabel new];
    desLabel.top = name.bottom;
    desLabel.left = name.left;
    desLabel.size = CGSizeMake(name.width, 20);
    desLabel.font = kFONT_TITLE(16);
    desLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:desLabel];
    _shopDescribe = desLabel;
    
    YYLabel *manCount = [YYLabel new];
    manCount.top = desLabel.bottom;
    manCount.left = desLabel.left;
    manCount.size = CGSizeMake(desLabel.width/2.0-5, 20);
    manCount.font = kFONT_TITLE(14);
    manCount.textColor = kRGBColor(102, 102, 102);
    manCount.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:manCount];
    _menCount = manCount;
    
    YYLabel *commentCount = [YYLabel new];
    commentCount.top = desLabel.bottom;
    commentCount.left = manCount.right+10;
    commentCount.size = CGSizeMake(desLabel.width/2.0-5, 20);
    commentCount.font = kFONT_TITLE(14);
    commentCount.textColor = kRGBColor(102, 102, 102);
//    commentCount.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:commentCount];
    _commentCount = commentCount;
    
    
    CALayer *addressImg = [CALayer layer];
    addressImg.contents = (__bridge id _Nullable)([UIImage imageNamed:@"adressback"].CGImage);
    addressImg.frame = CGRectMake(imgLayer.right + desLabel.width/4.0-12, commentCount.bottom + 5 + 10, 12, 16);
    [self.contentView.layer addSublayer:addressImg];
    
    YYLabel *area = [YYLabel new];
    area.top = commentCount.bottom + 5 + 10;
    area.left = addressImg.right + 5;
    area.size = CGSizeMake(55, 20);
    area.font = kFONT_TITLE(14);
    area.textColor = kRGBColor(102, 102, 102);
    area.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:area];
    _addressArea = area;
    
    
    YYLabel *shopDesLabel = [YYLabel new];
    shopDesLabel.top = area.top;
    shopDesLabel.left = area.right + 10;
    shopDesLabel.size = CGSizeMake(desLabel.width/2.0 - 5, 20);
    shopDesLabel.font = kFONT_TITLE(14);
    shopDesLabel.textColor = kRGBColor(102, 102, 102);
    [self.contentView addSubview:shopDesLabel];
    _moreMsg = shopDesLabel;
    _moreMsg.text = @"更多优惠";
    
    CALayer *line = [CALayer layer];
    line.backgroundColor = kRGBColor(102, 102, 102).CGColor;
    line.frame = CGRectMake(manCount.right + 4.5, desLabel.bottom + 3 , 1, 20-6);
    [self.contentView.layer addSublayer:line];
    
    CALayer *line2 = [CALayer layer];
    line2.backgroundColor = kRGBColor(150, 150, 150).CGColor;
    line2.frame = CGRectMake(manCount.right - 25, commentCount.bottom + 5, 60, 1);
    [self.contentView.layer addSublayer:line2];
    
    
    CALayer *line3 = [CALayer layer];
    line3.backgroundColor = kRGBColor(150, 150, 150).CGColor;
    line3.frame = CGRectMake(area.right + 4.5, line2.bottom + 3 + 10 , 1, 20 - 6);
    [self.contentView.layer addSublayer:line3];

    
    CALayer *line4 = [CALayer layer];
    line4.backgroundColor = kRGBColor(150, 150, 150).CGColor;
    line4.frame = CGRectMake(0, viewHeight - 0.5, kWindowW, 0.5);
    [self.contentView.layer addSublayer:line4];
}

- (void)setShopModel:(JCutShopDetailModel *)shopModel
{
    _shopModel = shopModel;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:shopModel.BannersList.firstObject]]];
        _imgLayer.contents = (__bridge id _Nullable)(img.CGImage);
        
        _shopName.text = [NSString stringWithFormat:@"%@   %@",shopModel.ShopName,shopModel.Type];
        _menCount.text = [NSString stringWithFormat:@"人气 %ld",(long)shopModel.TotalSales];
        _commentCount.text = [NSString stringWithFormat:@"评论 %ld",shopModel.CommentCount];
        _addressArea.text = shopModel.ShopNameTip;
        _shopDescribe.text = [NSString stringWithFormat:@"(%@)",shopModel.ShortAddress];
    });
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
